package com.hbnu.commonclass;

import com.hbnu.object.Person;

/**
 * 用户类
 *
 * @author kittychen
 * @date 2025-09-23 10:18
 */
public class User {
    private String username;
    private int age;
    public User(String username, int age) {
        this.username = username;
        this.age = age;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "User===>" +
                "username='" + username + '\'' +
                ", age=" + age;
    }

    @Override
    public boolean equals(Object obj) {
        // 1、判断传入的对象是否为null
        if (null == obj) {
            return false;
        }

        // 2、判断传入的对象是否为当前对象
        if (this == obj) {
            return true;
        }

        // 3、判断传入的对象所属类型是否和当前对象属性类型是同一类型
        if (!(obj instanceof User)) {  // 传入的类型和当前类型不是同一个类型
            return false;
        }

        User user = (User) obj;   // 将传进来的对象转成当前类型的对象
        return this.age == user.age && this.username.equals(user.username);
    }
}
